import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/Home'
  },
  {
    path: '/Home',
    name: 'Home',
    component: Home
  },
  {
    path: '/goodsdetail/:title/:index',
    name: 'GoodsDetail',
    component: ()=>import('@/views/GoodsDetail.vue')
  },
  {
    path: '/Login',
    name: 'Login',
    component: ()=>import('@/views/Login.vue')
  }
]

const router = new VueRouter({
  routes
})

router.beforeEach((to,from,next)=>{
  const token = sessionStorage.getItem('token')
  // console.log(token);
  if(to.path == "/login" || token) return next()
  next({path: "/login"})
})

export default router
